package com.ruoyi.web.controller.app;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.app.domain.vo.AppPackageOrderVo;
import com.ruoyi.app.domain.bo.AppPackageOrderBo;
import com.ruoyi.app.service.IAppPackageOrderService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * APP用户套餐订单
 *
 * @author ruoyi
 * @date 2025-06-21
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/packageOrder")
public class AppPackageOrderController extends BaseController {

    private final IAppPackageOrderService iAppPackageOrderService;

    /**
     * 查询APP用户套餐订单列表
     */
    @SaCheckPermission("system:packageOrder:list")
    @GetMapping("/list")
    public TableDataInfo<AppPackageOrderVo> list(AppPackageOrderBo bo, PageQuery pageQuery) {
        return iAppPackageOrderService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出APP用户套餐订单列表
     */
    @SaCheckPermission("system:packageOrder:export")
    @Log(title = "APP用户套餐订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(AppPackageOrderBo bo, HttpServletResponse response) {
        List<AppPackageOrderVo> list = iAppPackageOrderService.queryList(bo);
        ExcelUtil.exportExcel(list, "APP用户套餐订单", AppPackageOrderVo.class, response);
    }

    /**
     * 获取APP用户套餐订单详细信息
     *
     * @param packageOrderId 主键
     */
    @SaCheckPermission("system:packageOrder:query")
    @GetMapping("/{packageOrderId}")
    public R<AppPackageOrderVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long packageOrderId) {
        return R.ok(iAppPackageOrderService.queryById(packageOrderId));
    }

    /**
     * 新增APP用户套餐订单
     */
    @SaCheckPermission("system:packageOrder:add")
    @Log(title = "APP用户套餐订单", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody AppPackageOrderBo bo) {
        return toAjax(iAppPackageOrderService.insertByBo(bo) ? 1 : 0);
    }

    /**
     * 修改APP用户套餐订单
     */
    @SaCheckPermission("system:packageOrder:edit")
    @Log(title = "APP用户套餐订单", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody AppPackageOrderBo bo) {
        return toAjax(iAppPackageOrderService.updateByBo(bo) ? 1 : 0);
    }

    /**
     * 删除APP用户套餐订单
     *
     * @param packageOrderIds 主键串
     */
    @SaCheckPermission("system:packageOrder:remove")
    @Log(title = "APP用户套餐订单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{packageOrderIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] packageOrderIds) {
        return toAjax(iAppPackageOrderService.deleteWithValidByIds(Arrays.asList(packageOrderIds), true) ? 1 : 0);
    }
}
